package com.gagakuai.bpm.dao.mapper.camunda;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gagakuai.bpm.domian.dto.scheduleTask.BPMUserVo;
import com.gagakuai.bpm.domian.dto.scheduleTask.DeptInfo4Bmp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SyncUserInfoMapper extends BaseMapper<BPMUserVo> {

    @Update(" update ACT_ID_USER set FIRST_ = #{userName} where ID_ = #{userId} ")
    int updateUser(@Param("userId")String userId, @Param("userName") String userName);

    @Update(" <script> " +
            " <foreach collection = 'deptInfoList' item = 'item' separator = ';' > " +
            "  insert into ACT_ID_GROUP (ID_, NAME_) values   " +
            "  ( #{item.deptId}, #{item.name} ) " +
            " ON DUPLICATE KEY UPDATE NAME_ = #{item.name} " +
            " </foreach>  " +
            " </script> ")
    int updateDept(@Param("deptInfoList") List<DeptInfo4Bmp> deptInfoList);

    @Delete(" <script> " +
            " delete from ACT_ID_MEMBERSHIP where  USER_ID_ = #{userId}  and  GROUP_ID_ in " +
            " <foreach collection = 'deptInfoList' item = 'item' separator = ',' open = '(' close = ')' > " +
            "  #{item.deptId} " +
            "  </foreach> " +
            " </script> " )
    void deleteShip(@Param("userId")String userId, @Param("deptInfoList") List<DeptInfo4Bmp> deptInfoList);

    @Insert(" <script> " +
            " insert into ACT_ID_MEMBERSHIP (USER_ID_, GROUP_ID_) values " +
            " <foreach collection = 'deptInfoList' item = 'item' separator = '),(' open = '(' close = ')' > " +
            " #{userId}, #{item.deptId} " +
            "  </foreach> " +
            " </script> " )
    int insertShip(@Param("userId")String userId, @Param("deptInfoList") List<DeptInfo4Bmp> deptInfoList);
}
